package com.yael.utils;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class EmailServise {

	public void send(String to, String toAlias, String from, String fromAlias, String subject, String body){
		 	
			if(to==null || from==null) return; 
		
			Properties props = new Properties();
	        Session session = Session.getDefaultInstance(props, null);

	        try {
	            Message msg = new MimeMessage(session);
	            msg.setFrom(new InternetAddress(from, fromAlias));
	            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to, toAlias));
	            if(subject!=null) msg.setSubject(subject);
	            if(body!=null) msg.setText(body);
	            Transport.send(msg);
	    
	        } catch (AddressException e) {
	            // ...
	        } catch (MessagingException e) {
	            // ...
	        } catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
}
